/**
 * 快慢双指针，快指针一直走，当快指针不等于 0 就和慢指针交换，慢指针加一
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */

const moveZeroes = nums => {
  const fun = (arr, l, r) => {
    let temp = arr[l]
    arr[l] = arr[r]
    arr[r] = temp
  }

  let l = 0, r = 0
  while (r < nums.length) {
    if (nums[r] !== 0) {
      fun(nums, l, r)
      l++
    }
    r++
  }
  return nums
}

console.log(moveZeroes([2, 3, 0, 1, 0, 0]))